﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YBApproval.IDAL;
using YBApproval.Model;
using System.Data.Entity;

namespace YBApproval.EFDAL
{
    public class InstanceValueDAL : IInstanceValue
    {
        private YBDbContext db = new YBDbContext();

        public List<InstanceValue> GetValues(string recordId)
        {
            var values = from iv in db.InstanceValues.Include(p => p.Field)
                         where iv.RecordId == recordId
                         select iv;
            return values.ToList();
        }

        //public void SaveValues(List<InstanceValue> values)
        //{
        //    //Guid guid = Guid.NewGuid();
        //    for (int i = 0; i < values.Count; i++)
        //    {
        //        //values[i].RecordId = guid;
        //        //values[i].Field = null;
        //        db.InstanceValues.Add(values[i]);
        //    }
        //    db.SaveChanges();
        //}

        //public void DeleteValues(Guid instanceId)
        //{
        //    List<InstanceValue> values = db.InstanceValues.Where(iv => iv.RecordId == instanceId).ToList();
        //    for (int i = 0; i < values.Count; i++)
        //    {
        //        db.InstanceValues.Remove(values[i]);
        //    }
        //    db.SaveChanges();
        //}

        public void Dispose()
        {
            db.Dispose();
        }
    }
}
